#ifndef ENCODER_H
#define ENCODER_H

#include <iostream>
#include <vector>
#include <cstdint>
#include <stdexcept>
#include <gmpxx.h>
#include "context.h"
#include "ring.h"
#include "operand.h"
#include "utils.h"
#include "ring_scaling.h"

using namespace std;
/* *
 * @class Encoder
 * @brief 同态加密中的编码器，负责对明文数据进行编码和解码操作。
 *
 * 该类用于将明文数据编码成适合同态加密操作的格式，并提供解码功能。它还支持在同态加密过程中进行缩放操作。
 */
class Encoder {
public:
    Context *params;
    std::vector<uint64_t> indexMatrix;
    std::vector<uint64_t> rescaleParams;
    RNSScaler *scaler;
    Poly *tmpPoly;
    PlaintextRingT *tmpPtRt;

    Encoder(Context *params);
    // 拷贝构造函数
    Encoder(const Encoder &other);
    Encoder &operator = (const Encoder &other);
    // 移动构造函数
    Encoder(Encoder &&other) = delete;
    Encoder &operator = (Encoder &&other) = delete;
    ~Encoder();
    void EncodeUint(const std::vector<uint64_t> &coeffs, Plaintext *pt);
    void EncodeUintRingT(const std::vector<uint64_t> &coeffs, PlaintextRingT *pt);
    void ScaleUp(PlaintextRingT *ptRt, Plaintext *pt);
    void ScaleDown(Plaintext *pt, PlaintextRingT *ptRt) const;
    void DecodeRingT(void *p, PlaintextRingT *ptRt);
    void DecodeUint(void *p, std::vector<uint64_t> &coeffs);
    std::vector<uint64_t> DecodeUintNew(void *p);
    void ScaleUp(Ring *ringQ, Ring *ringT, std::vector<uint64_t> &tmp, Poly *pIn, Poly *pOut);
};


#endif // ENCODER_H